"""新建联系人页面"""
from page.base_page import BasePage
from selenium.webdriver.common.by import By

class NewContactPage(BasePage):

    url = '/crm5/index.php?m=contacts&a=add'

    #定位器
    # 新建联系人姓名
    name_locator = (By.ID, "name")
    # 所属客户
    customer_name_locator = (By.ID, 'customer_name')
    # 选择客户
    choice_customer_locator = (By.CSS_SELECTOR,
                               '#datas > tr:nth-child(1) > td:nth-child(1) > input[type=radio]:nth-child(1)')
    #职位
    position_locator = (By.NAME, "post")
    # QQ
    qq_no_locator = (By.NAME, 'qq_no')
    # email
    email_no_locator = (By.NAME, 'zip_code')
    # 确认
    btn_sure_locator = (By.XPATH, '/html/body/div[7]/div[3]/div/button[1]/span')
    # 保存
    btn_save_locator = (By.CSS_SELECTOR,
                        'body > div.container > div.row > div > form > table > tfoot > tr > td:nth-child(2) > input:nth-child(1)')

    def input_name(self,contact_name):
        """ 输入联系人姓名"""
        self.driver.find_element(*self.name_locator).send_keys(contact_name)

    def click_contact_name(self):
        """点击所属客户"""
        self.driver.find_element(*self.customer_name_locator).click()

    def choice_contact_name(self):
        """选择客户"""
        self.driver.find_element(*self.choice_customer_locator).click()

    def input_position(self,position):
        """输入职位"""
        self.driver.find_element(*self.position_locator).send_keys(position)

    def input_qq_no(self,qq_no):
        """输入QQ"""
        self.driver.find_element(*self.qq_no_locator).send_keys(qq_no)

    def input_email(self,email):
        """输入邮编"""
        self.driver.find_element(*self.email_no_locator).send_keys(email)

    def click_sure(self):
        """点击确认"""
        self.driver.find_element(*self.btn_sure_locator).click()

    def click_save(self):
        """点击保存"""
        self.driver.find_element(*self.btn_save_locator).click()